package com.zte.warehouse.control;


import com.zte.sys.login.model.LUsers;
import com.zte.util.OperatorLog;
import com.zte.util.PageModel;
import com.zte.util.ResultMessage;
import com.zte.warehouse.model.*;
import com.zte.warehouse.service.IStockService;
import com.zte.warehouse.service.IWarehouseService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 库存管理模块
 * <p>
 * 库存管理管理模块使用者：财务部门经理  job_id=6
 * 创建仓库权限：财务部门经理
 */


@Controller
@RequestMapping("/Stock")
public class StockAction {
    @Autowired
    private IStockService iStockService;
    @Autowired
    private RedisTemplate redisTemplate;


    @RequestMapping("/StockPage")
    @ResponseBody
    @OperatorLog(operate="多条件库存列表查询分页", module="库存管理")
    public ResultMessage getStockPage(PageModel<Stock> pageModel, StockCondition conn) {

        //1.身份验证：判断用户jobID, 财务部门经理看全部,非财务部门经理看自己
        LUsers User = (LUsers) redisTemplate.opsForValue().get(conn.getUserID() + "");
        ResultMessage msg = new ResultMessage();
        if (User != null) {
            if (User.getJobId() == 6l||User.getJobId() == 1l) {//财务部门经理，总经理
                conn.setUserID(null);
                System.out.println("JobId:"+User.getJobId());
            }
            System.out.println("NowUser:" + User);
        }
        PageModel<Stock> stockPageModel = iStockService.queryStockPageByCondition(pageModel, conn);
        msg.setStatus(200);
        msg.setMsg("查询成功！");
        msg.setData(stockPageModel);

        System.out.println(stockPageModel);

        return msg;
    }

}
